﻿<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="ServerTree.ascx.cs"
    Inherits="LongSpeed.WebSite.UserControl.ServerTree" %>

<%@ Import Namespace="LongSpeed.WebSite.Behaviors" %>
<script src="../Scripts/treeview/jquery.treeview.js" type="text/javascript"></script>
<link href="../Scripts/treeview/jquery.treeview.css" rel="stylesheet" type="text/css" />
<div class="sblock1">
    <div class="sblock1-top">
        久速数据中心</div>
    <div class="sblock1-bottom">
        <%         
            Dictionary<int, Memu> memusDic = Session[LongSpeed.WebSite.Behaviors.SessionString.MemuStr] as Dictionary<int, Memu>;
            IList<Memu> memus = null;
            if (memusDic == null)
            {
                LongSpeed.WebSite.Behaviors.Memu m = new LongSpeed.WebSite.Behaviors.Memu();
                memus = m.GetMemu(new LongSpeed.WebSite.Behaviors.Memu() { ID = 0 }, true).OrderBy(o => o.SortIndex).ToList();
                this.Cache[LongSpeed.WebSite.Behaviors.SessionString.MemuStr] = memus.ToDictionary(o => o.ID);
            }
            else
            {
                memus = memusDic.Values.ToList();
            }
            if (memus != null && memus.Count > 0)
            {
        %>
        <ul id="navigation">
            <%
                for (int i = 0; i < memus.Count; i++)
                {
                    var pm = memus[i];
                    string pma = string.Format("<a><span>{1}</span></a>", i, pm.Name);
            %>
            <li>
                <%
                    Response.Write(pma);
                    if (pm.ChildMemu != null && pm.ChildMemu.Count > 0)
                    {                        
                %>
                <ul>
                    <%
                        for (int j = 0; j < pm.ChildMemu.Count; j++)
                        {
                            var cm = pm.ChildMemu[j];
                            string cma;
                            if (!string.IsNullOrEmpty(cm.AlternateField3) && !string.IsNullOrWhiteSpace(cm.AlternateField3))
                            {
                                cma = string.Format("<a href=\"../{0}?{1}.{2}\">{3}</a>", cm.AlternateField3, i, j, cm.Name);
                            }
                            else
                            {
                                cma = string.Format("<a href=\"../room-{0}-{1}.html?{2}.{3}\">{4}</a>", cm.ID, pm.ID, i, j, cm.Name);
                            }                              
                    %>
                    <li>
                        <%=(cma) %></li>
                    <% 
                        }
                    %>
                </ul>
                <%
                    }
                %>
            </li>
            <%
                }
            %>
        </ul>
        <%
            }            
        %>
    </div>
</div>
<script type="text/javascript" language="javascript">
    $(document).ready(function () {
        $("#navigation").treeview({
            persist: "location",
            collapsed: true,
            unique: true
        });
    });
</script>